package org.example;

public class Test1 {
    //leetcode 复写零
    //https://leetcode.cn/problems/duplicate-zeros/description/
    public void duplicateZeros(int[] arr) {
        int n = arr.length;
        int slow = 0, fast = -1;
        while (fast < n - 1) {
            if (arr[slow] == 0) fast += 2;
            else fast++;
            if (fast >= n-1) break;
            slow++;
        }
        if (fast == n) {
            arr[n-1] = 0;
            slow--;
            fast = n-2;
        }
        while (slow >= 0) {
            if (arr[slow] == 0) {
                arr[fast--] = 0;
                arr[fast--] = 0;
                slow--;
            }else {
                arr[fast--] = arr[slow--];            }
        }
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        int[] arr = {8,4,5,0,0,0,0,7};
        test1.duplicateZeros(arr);
        System.out.println(444);
    }
}
